package com.example.demo.index.web;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.annotation.ApiDesc;
import com.example.demo.entity.LoginEnity;
import com.example.demo.entity.base.ResponseBean;
import com.example.demo.entity.base.ResponseEntity;
import com.example.demo.index.service.HomepageService;
import com.example.demo.util.RequestLoginCache;
import com.example.demo.util.ResponseFactory;
import com.example.demo.util.TokenUtil;

@RestController
@RequestMapping(value="/index/homepage")
public class HomepageController {
	
	@Autowired
	private HomepageService homepageService;
	
	@ApiDesc("从缓存中取出登陆信息")
	@RequestMapping(value="/getlogininfofromcache")
	public ResponseEntity<LoginEnity> getLoginInfoFromCache(HttpServletRequest request){
		
		return ResponseFactory.setObject(RequestLoginCache.get());		
	}
	
	@ApiDesc("查询用户所拥有菜单列表")
	@RequestMapping(value="/getloginmenus",method=RequestMethod.GET)
	public ResponseBean getLoginMenus(HttpServletRequest request) {
		
		String token = TokenUtil.getTokenFromRequest(request);
		
		ResponseBean ret = homepageService.getLoginMenus(token);
		
		return ret;				
	}
}
